package com.tmusoft.controller;

import com.tmusoft.domain.AjaxResult;
import com.tmusoft.service.FileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@Api(tags = "文件上传接口")
@RestController
@RequestMapping("/api/upload")
public class UploadController {


    @Autowired
    private FileService fileService;

    @ApiOperation("文件上传")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type",value = "文件类型，1：图片，2：文件", dataType = "String")
    })
    @PostMapping("/uploadFile")
    public AjaxResult uploadMaterial(@RequestParam("file") MultipartFile multipartFile,
                                     @RequestParam("type") String type,
                                     @RequestParam("token") String token, String folder) {
        return fileService.uploadFile(multipartFile, type, folder, token);
    }


}
